/**
 * @desc 总线入口 控制层 初始化绘制、绘图
 */

import { ctrlInitFun } from './ctrl';
import { drawLeafletInitFun } from './drawLeaflet';

export const allInitFun = (allData, viewer, cb) => {
  // 每一个绘制函数步进调用
  const _stepFun = (i) => {
    const element = allData[i];
    if (!element) {
      cb && cb();
      return;
    }
    let { type, payload } = element;
    switch (type) {
      case 'ctrl':
        ctrlInitFun(payload, viewer);
        break;
      case 'draw':
        drawLeafletInitFun(payload, viewer);
        break;
      default:
        break;
    }
    // 每个步骤增加一个时间间隔
    setTimeout(() => {
      _stepFun(i + 1);
    }, 200);
  };
  _stepFun(0);
};
